package lesson11;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author tongchen
 * @create 2023-02-08 22:10
 */
public class MyThread01 {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();
         Thread t1 =new Thread(()->{
             System.out.println("在执行任务.....");
                 });
         t1.start();
     Runnable runnable=new Runnable() {
            @Override
            public void run() {
                System.out.println("执行任务");
            }
        };
     Thread thread=new Thread(runnable);
     thread.start();
       Callable callable= new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int a=10;
                int b=20;
                return a+b;
            }
        };
        FutureTask<Integer> integerFutureTask = new FutureTask<Integer>(callable);
        Thread t=new Thread(integerFutureTask);
        t.start();
        try {
            Integer integer = integerFutureTask.get();
            System.out.println("返回的结果为"+integer);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("执行线程任务....");
    }
}